<template>
	<view class="about-container">
		<custom-navbar title="" button-bg-type=2></custom-navbar>

		<!-- 第一行：显示今天的日期 -->
		<view class="date-display">
			{{ todayDate }}
		</view>

		<!-- 第二行：显示记录每天心情 -->
		<view class="mood-record">
			记录 每天心情~
		</view>

		<!-- 第三行：文本域和提交按钮 -->
		<view class="login-form-content">
			<view class="editor-section">
				<textarea v-model="checkerForm.checkText" class="editor" placeholder="我想说..."></textarea>

				<button @click="handleChecker()" class="submit-button">提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		addCheck
	} from '@/api/system/check';

	export default {
		data() {
			return {
				moodText: '', // Text area content
				todayDate: '', // Current date
				checkerForm: {
					checkText: "",

				}
			};
		},
		mounted() {
			this.todayDate = this.formatDate(new Date());
		},
		methods: {
			// 注册方法
			async handleChecker() {
				if (this.checkerForm.checkText === "") {
					this.$modal.msgError("请输入您的心情")

				} else {
					this.$modal.loading("发表中，请耐心等待...")
					this.checker()
				}
			},
			// 用户注册
			async checker() {
				let baiCheck = {};
				baiCheck.content = this.checkerForm.checkText;
				//baiCheck.userId=9;
				addCheck(baiCheck).then(res => {
					this.$modal.closeLoading()
					//this.$modal.msgSuccess("恭喜你， 发表心情成功");
					//this.$tab.switchTab('/pages/index');
					this.$modal.confirm("恭喜你， 发表心情成功", '系统提示')
					this.$tab.reLaunch('/pages/index')
					//  msgSuccess.showModal({
					// 	title: "系统提示",
					// 	content: "恭喜你， 发表心情成功！",
					// 	success: function (res) {
					// 		if (res.confirm) {
					//          //uni.redirectTo({ url: `/pages/index` });
					// //this.$tab.reLaunch('/pages/index')
					// this.$tab.switchTab('/pages/index');
					// // uni.switchTab({
					// // 	url:`/pages/index`
					// // })
					// 		}
					// 	}
					// })
				}).catch(() => {
					if (this.captchaEnabled) {
						this.$modal.msgError("发布您的心情失败")
					}
				})
			},
			// 注册成功后，处理函数
			registerSuccess(result) {
				// 设置用户信息
				console.log("注册成功?");
				this.$store.dispatch('GetInfo').then(res => {
					this.$tab.reLaunch('/pages/index')
				})
			},
			formatDate(date) {
				const options = {
					month: 'long',
					day: 'numeric',
					weekday: 'long'
				};
				return date.toLocaleDateString('zh-CN', options).replace(/星期/, ' 星期 ');
			}
		}
	};
</script>

<style scoped>
	.about-container {
		background: url(/static/images/checkbg.png) no-repeat fixed center;
		background-color: #fff;
		padding: 20px;
		height: 100%;
		min-height: 100vh;
		background-position: top;
		background-size: contain;
	}

	.date-display {
		font-size: 14px;
		color: #333;
		margin-bottom: 10px;
		margin-top: 300px;
	}

	.mood-record {
		font-size: 32px;
		font-weight: normal;
		color: #000;
		margin-bottom: 20px;
	}

	.editor-section {
		display: flex;
		flex-direction: column;
		gap: 10px;
	}

	.editor {
		width: 100%;
		padding: 10px;
		border: 1px solid #fff;
		border-radius: 10px;
		background-color: #fff;
		box-sizing: border-box;
	}

	.submit-button {
		width: 80px;
		align-self: flex-end;
		background-color: #28a745;
		color: #fff;
		padding: 5px;
		border: none;
		border-radius: 10px;
		cursor: pointer;
		margin-right: 20px;
	}

	.submit-button:hover {
		background-color: #218838;
	}
</style>